package de.hska.pwmanager.persistence.model.dao;

import java.util.List;

import org.springframework.transaction.annotation.Transactional;
import org.synyx.hades.dao.GenericDao;
import org.synyx.hades.dao.Modifying;
import org.synyx.hades.dao.Query;

import de.hska.pwmanager.persistence.model.*;

public interface PasswordDataDao extends GenericDao<PasswordData, Long> {
	@Modifying
	@Transactional
	@Query("update PasswordData u set u.passwordCategory = ?1 where u.id = ?2")
	PasswordData setCategory(PasswordCategory passwordCategory, Long passwordDataID);
	
	//SELECT x FROM Magazine x join fetch x.articles WHERE x.title = 'JDJ'
	// SELECT x FROM Magazine x, IN(x.articles) y WHERE y.authorName = 'John Doe'

//	@Transactional
//	@Query("SELECT distinct pwdata FROM PasswordData pwdata join pwdata.passwordUserHashs pwhash where pwhash.user.id = ?1")
	@Query("SELECT pwdata FROM PasswordData pwdata, IN(pwdata.passwordUserHashs) userhash WHERE userhash.user = ?1")
	public List<PasswordData> getUserPasswords(User user);
	
	
	public List<PasswordData> findByTitle(String title);
	public List<PasswordData> findByPasswordCategory(PasswordCategory passwordCategory);
	
	public List<PasswordData> findByTitleAndIdNot(String title, Long id);
}
